/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.weapon;

import ace.game.entity.bullet.BulletData;
import ace.game.Sprite;
import ace.system.Utilities;
import ace.system.xml.XmlNode;

/**
 *
 * @author Hallucinogen
 */
public class WeaponData {
	protected WeaponData() {
		mSprite		= null;
		mName			= "Weapon";
		mDescription	= "Simple weapon";
		mPrice			= 0;
		mReloadTime		= 0;
        mSplitCount     = 1;
        mSpreadCount    = 1;
        mBulletPerWave  = 1;
	}

	public WeaponData(XmlNode xml) {
		//Initialize
		this();

        // set index
        mIndex = Integer.parseInt(xml.getAttribute("index"));

		//Prepare variable
		XmlNode imageNode	= null;

		//For each node
		for(int i=0, n = xml.getChildren().size(); i < n; ++i) {
			//Get tag name and it's value
			XmlNode Node	= ((XmlNode)xml.getChildren().elementAt(i));
			String Tag		= Node.getNodeName();
			String Value	= ((XmlNode)Node.getChildren().elementAt(0)).getNodeValue();

			//Save data
			if (Tag.equals("sprite"))               imageNode		= (XmlNode)xml.getChildren().elementAt(i);
                else if (Tag.equals("name"))		mName			= Value;
			else if (Tag.equals("price"))           mPrice			= Integer.parseInt(Value);
			else if (Tag.equals("reload"))          mReloadTime		= Integer.parseInt(Value);
			else if (Tag.equals("description"))     mDescription	= Value;
			else if (Tag.equals("type"))            mWeaponType		= Integer.parseInt(Value);
			else if (Tag.equals("weapon-type"))     mWeaponType		= Integer.parseInt(Value);
			else if (Tag.equals("bullet"))          mBulletData		= new BulletData(Node);
			else if (Tag.equals("seeking"))         mSeeking		= Integer.parseInt(Value) == 1;
            else if (Tag.equals("split"))           mSplitCount		= Integer.parseInt(Value);
            else if (Tag.equals("spread"))          mSpreadCount	= Integer.parseInt(Value);
            else if (Tag.equals("bullet-per-wave")) mBulletPerWave	= Integer.parseInt(Value);
            else if (Tag.equals("wave-reload"))     mWaveReload     = Integer.parseInt(Value);
		}

		//Create sprite
		if (imageNode != null) {
			mSprite = new Sprite(imageNode, Utilities.WEAPON_FOLDER);
		}
	}

	public String getName()				{   return mName;             }
	public int getPrice()				{   return mPrice;            }
	public int getReloadTime()			{   return mReloadTime;       }
	public String getDescription()		{   return mDescription;      }
	public Sprite getSprites()			{   return mSprite;           }
	public BulletData getBulletData()	{   return mBulletData;       }
	public int getWeaponType()			{   return mWeaponType;       }
    public boolean isSeeking()          {   return mSeeking;          }
    public int getSplitCount()          {   return mSplitCount;       }
    public int getSpreadCount()         {   return mSpreadCount;      }
    public int getBulletPerWave()       {   return mBulletPerWave;    }
    public int getWaveReload()          {   return mWaveReload;       }
    public int getIndex()               {   return mIndex;            }

	// gameplay data
	private String mName, mDescription;
	private int mPrice;
	private int mReloadTime;
    private int mIndex;

    // shooting stuffs
	private BulletData mBulletData;
    private boolean mSeeking;
    private int mSplitCount;
    private int mSpreadCount;
    private int mBulletPerWave;
    private int mWaveReload;

	// weapon type = weapon position
	private int mWeaponType;
	//Images
	protected Sprite mSprite;

	public static final int WEAPON_TYPE_MAIN		= 0;
	public static final int WEAPON_TYPE_LEFT		= 1;
	public static final int WEAPON_TYPE_RIGHT		= 2;
	public static final int WEAPON_TYPE_CIRCULAR	= 3;
}
